package com.ye.personnel.controller;

import com.ye.personnel.api.flow.*;
import com.ye.personnel.api.gwy.GwyMemberListVo;
import com.ye.personnel.common.page.BasePageParam;
import com.ye.personnel.common.page.PageModel;
import com.ye.personnel.common.response.BaseResult;
import com.ye.personnel.service.FlowService;
import com.ye.personnel.service.GwyCmsSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: yeubo
 * @Date: 2024/1/2 19:01
 */
@RestController
@RequestMapping("flow")
@Api(tags = "审核流程相关")
public class FlowController {

    @Autowired
    FlowService flowService;
    @Autowired
    GwyCmsSystemService gwyCmsSystemService;

    @GetMapping("flowList")
    @ApiOperation("流程列表")
    public BaseResult<PageModel<FlowListVo>> flowList(FlowListSearch search){
        PageModel<FlowListVo> flowListVoPageModel = flowService.flowList(search);
        return new BaseResult<PageModel<FlowListVo>>().ok(flowListVoPageModel);
    }

    @GetMapping("flowDetail")
    @ApiOperation("流程详情")
    public BaseResult<FlowDetailVo> flowDetail(@RequestParam("flowId") String flowId){
        FlowDetailVo flowDetailVo = flowService.flowDetail(flowId);
        return new BaseResult<FlowDetailVo>().ok(flowDetailVo);
    }

    @PostMapping("startFlowDto")
    @ApiOperation("发起流程")
    public BaseResult<String> startFlow(@RequestBody StartFlowDto startFlowDto){
        boolean result = flowService.startFlow(startFlowDto);
        if(result){
            return new BaseResult<String>().success("流程发起成功，等待审核");
        }
        return new BaseResult<String>().error("流程发起失败");
    }

    @PostMapping("checkFlow")
    @ApiOperation("审核流程")
    public BaseResult<String> checkFlow(@RequestBody CheckFlowDto checkFlowDto){
        boolean result = flowService.checkFlow(checkFlowDto);
        if(result){
            return new BaseResult<String>().success("流程审核成功");
        }
        return new BaseResult<String>().error("流程审核失败");
    }

    @GetMapping("flowNoticeList")
    @ApiOperation("流程提醒列表")
    public BaseResult<PageModel<FlowNoticeListVo>> flowNoticeList(BasePageParam pageParam){
        PageModel<FlowNoticeListVo> pageModel = flowService.flowNoticeList(pageParam);
        return new BaseResult<PageModel<FlowNoticeListVo>>().ok(pageModel);
    }

    @GetMapping("memberList")
    @ApiOperation("员工列表,departmentNo 单位编码，不传默认当前登录者所在的单位编码")
    public BaseResult<List<GwyMemberListVo>> memberList(@RequestParam(value = "departmentNo") String departmentNo){
        List<GwyMemberListVo> memberList = gwyCmsSystemService.getMemberList(departmentNo);
        return new BaseResult<List<GwyMemberListVo>>().ok(memberList);
    }

    @GetMapping("personnelDetail")
    @ApiOperation("人员任免表")
    public BaseResult<PersonnelDetailVo> personnelDetail(@RequestParam(value = "personnelNo") String personnelNo){
        PersonnelDetailVo personnelDetailVo = gwyCmsSystemService.personnelDetail(personnelNo);
        return new BaseResult<PersonnelDetailVo>().ok(personnelDetailVo);
    }
}
